package com.bailan.foreat.mapper;

import com.bailan.foreat.entity.Comment;
import com.bailan.foreat.vo.CommentVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ste
 * @since 2023-02-21 07:50:43
 */
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    @Select("<script>"+
            "select tc.content,tc.grade,tc.create_time createTime," +
            "tu.username,tu.user_img userImg," +
            "tp.product_name productName " +
            "from t_comment tc INNER JOIN t_user tu inner JOIN t_product tp " +
            "on tc.user_id=tu.id and tc.product_id=tp.id" +
            "<where>" +
            "<if test='productId != 0'>" +
            "product_id=#{productId} " +
            "</if>" +
            "</where>" +
            "ORDER BY create_time desc"+
            "</script>")
    IPage<CommentVo> selectByProductId(Page<CommentVo> page, Integer productId);
}
